/*
 * Copyright 2007-2008, www.jsemantic.org, www.adolfoestevez.com,
 * http://semanticj2ee.blogspot.com/ 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jsemantic.servicerules.examples.energy;

import java.util.Random;

import org.jsemantic.servicerules.examples.energy.model.Customer;
import org.jsemantic.servicerules.examples.energy.model.MeterReading;

/**
 * The Class MockDataGeneration.
 */
public class MockDataGeneration {

	/**
	 * Gets the customer.
	 * 
	 * @return the customer
	 */
	public Customer getCustomer() {
		Customer customer = new Customer();
		customer.setId(generateCustomerId());
		customer.setTariff(generateTariff());
		return customer;
	}

	/**
	 * Gets the meter reading.
	 * 
	 * @return the meter reading
	 */
	public MeterReading getMeterReading() {
		MeterReading reading = new MeterReading();
		reading.setMeterId(generateMeterId());
		reading = generateReadings(reading);
		return reading;
	}

	/**
	 * Generate readings.
	 * 
	 * @param reading the reading
	 * 
	 * @return the meter reading
	 */
	private MeterReading generateReadings(MeterReading reading) {

		Random seed = new Random();

		int previous = seed.nextInt() % 200000;
		if (previous < 0) {
			previous *= -1;
		}

		int actual =  (seed.nextInt() % 10000);
		if (actual < 0) {
			actual *= -1;
		}
		
		actual+=previous;
		
		reading.setActualReading(new Integer(actual));
		reading.setPreviousReading(new Integer(previous));

		return reading;
	}

	/**
	 * Generate customer id.
	 * 
	 * @return the string
	 */
	private String generateCustomerId() {
		Random seed = new Random();

		long id = seed.nextLong() % 999999999999L;
		if (id < 0) {
			id *= -1;
		}

		return new Long(id).toString();

	}

	/**
	 * Generate meter id.
	 * 
	 * @return the string
	 */
	private String generateMeterId() {
		Random seed = new Random();

		long id = seed.nextLong() % 999999999L;
		if (id < 0) {
			id *= -1;
		}

		return new Long(id).toString();
	}

	/**
	 * Generate tariff.
	 * 
	 * @return the string
	 */
	private String generateTariff() {
		Random seed = new Random();

		int type = seed.nextInt() % 3;

		if (type <= 0) {
			type = 1;
		}

		String tariff = "2.0." + new Integer(type);
		return tariff;
	}

}
